//
//  RootHomeViewController.m
//  DemoProject
//
//  Created by hao on 2018/7/13.
//  Copyright © 2018年 hao. All rights reserved.
//

#import "RootZeroViewController.h"
#import "RootHeaderView.h"
#import "UserNotifiViewController.h"

@interface RootZeroViewController () <RootHeaderViewDelegate>

@end

@implementation RootZeroViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置TabBar的角标(必须先获取‘navigationController’的‘tabBarItem’才能设置成功)
    self.navigationController.tabBarItem.badgeValue = @"1";
    self.navigationItem.title = @"iOS基础";
    [self setupItem];
}

- (void)setupItem
{
    NSArray *classArr = @[[GestureViewController class],
                          [ControlEventViewController class],
                          [ViewPropertyViewController class],
                          [ScrollViewController class],
                          [TableViewController class],
                          [CollectionViewController class],
                          [PikerViewController class],
                          [DatePickerViewController class],
                          [TextFieldViewController class],
                          [TextViewViewController class],
                          [LabelViewController class],
                          [ButtonViewController class],
                          [SwitchViewController class],
                          [SegmentViewController class],
                          [SlideViewController class],
                          [StepperViewController class],
                          [ImageViewController class],
                          [ImagePickerViewController class],
                          [IndicatorViewController class],
                          [PageControlViewController class],
                          [ProgressViewViewController class],
                          [AlertViewController class],
                          [StackViewViewController class],
                          [TestWKWebViewController class],
                          [TestPageViewController class]];
    NSArray *titleArr = @[@"Gesture Recognition手势",
                          @"UIControl",
                          @"UIView",
                          @"UIScrollView",
                          @"UITableView",
                          @"UICollectionView",
                          @"UIPikerView",
                          @"UIDatePicker",
                          @"UITextField",
                          @"UITextView",
                          @"UILabel",
                          @"UIButton",
                          @"UISwitch(开关)",
                          @"UISegment(分段选择控件)",
                          @"UISlide",
                          @"UIStepper(- +控件)",
                          @"UIImageView",
                          @"UIImagePickerController",
                          @"UIActivityIndicatorView(旋转的菊花)",
                          @"UIPageControl",
                          @"UIProgressView",
                          @"UIAlertViewController",
                          @"UIStackView",
                          @"WKWebView",
                          @"UIPageViewController页切换控制器"];
    NSMutableArray<SettingItemModel *> *uiItemsArr = [NSMutableArray array];
    for (int i = 0; i < titleArr.count; i++) {
//        NSLog(@"class = %@", classArr[i]);
        SettingItemModel *item = [SettingItemModel settingItemDataWithTitle:titleArr[i] titleColor:nil type:CellRightViewTypeArrow rightViewBlock:nil controller:classArr[i]];
        [uiItemsArr addObject:item];
    }
    
    /** 第二组 */
    NSArray<Class> *sysLibClassArr = @[[UserNotifiViewController class],
                                       [ControlEventViewController class],
                                       ];
    NSArray *sysLibTitleArr = @[@"通知(UserNotifications库)",
                                @"UIControl",
                                ];
    NSMutableArray<SettingItemModel *> *sysLibItemsArr = [NSMutableArray array];
    for (int i = 0; i < sysLibTitleArr.count; i++) {
        SettingItemModel *item = [SettingItemModel settingItemDataWithTitle:sysLibTitleArr[i] titleColor:nil type:CellRightViewTypeArrow rightViewBlock:nil controller:sysLibClassArr[i]];
        [sysLibItemsArr addObject:item];
    }
    
    
    
    NSArray *array = @[uiItemsArr, sysLibItemsArr];
    NSArray<NSString *> *headTitleArr = @[@"UI控件", @"系统常用库"];
    for (int i = 0; i < headTitleArr.count; i++) {
        SettingGroupModel *groupModel = [[SettingGroupModel alloc] initWithSettingItems:array[i]];
        groupModel.groupHeadTitle = headTitleArr[i];
        groupModel.groupHeadHeight = 44.0;
        groupModel.groupFootHeight = 20;
        RootHeaderView *sectionView = [[RootHeaderView alloc] init];
        sectionView.groupModel = groupModel;
        sectionView.delegate = self;
        groupModel.groupHeadView = sectionView;
        [self.groupModelArr addObject:groupModel];
    }
    
    SettingItemModel *swiftBasis = [SettingItemModel settingItemDataWithTitle:@"Swift语法" titleColor:nil type:CellRightViewTypeArrow rightViewBlock:nil controller:[SwiftGrammarViewController class]];
    SettingGroupModel *swiftGroup = [[SettingGroupModel alloc] initWithSettingItems:@[swiftBasis]];
    swiftGroup.groupHeadHeight = 34;
    swiftGroup.groupHeadTitle = @"Swift";
    
    [self.groupModelArr addObject:swiftGroup];
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([self.groupModelArr[section] isOpen] || section == self.groupModelArr.count-1) {
        return self.groupModelArr[section].itemsArr.count;
    }
    return 0;
}

#pragma mark - RootHeaderViewDelegate
- (void)headViewLoadData:(RootHeaderView *)headerView
{
    [self.tableView reloadData];
}

@end



